package org.elanfox.cloud.common.web.base;

import io.jsonwebtoken.Claims;
import io.jsonwebtoken.Jwts;
import org.elanfox.cloud.common.web.properties.TokenProperties;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.stereotype.Component;

/**
 * @author allan
 * @version 1.0.0
 * @date 2/24/21
 */
@Component
@EnableConfigurationProperties(TokenProperties.class)
public class JwtProvider {
    @Autowired
    private TokenProperties tokenProperties;

    public Claims verify(String token) {
        try {
            return Jwts.parser()
                    .setSigningKey(tokenProperties.getSecretKey())
                    .parseClaimsJws(token).getBody();
        } catch (Exception ignore) {
            return null;
        }
    }
}
